﻿using AutoMapper;
using BCCommon.Enums;
using BCDto.WeChatComponent.WeChatUser;
using BCEntity.WeChatComponent.WeChatUserInfo;
using System;
using System.Collections.Generic;
using System.Text;

namespace BCService.MapperProfiles
{
    public class WeChatUserInfoProfile : Profile
    {
        public WeChatUserInfoProfile()
        {
            CreateMap<WeChatUserInfoEntity, WeChatUserInfoDto>()
                 .ForMember(p => p.Sex, dto => dto.MapFrom(s => (WeChatUserSexType)Enum.Parse(typeof(WeChatUserSexType),s.Sex)))
                .IgnoreAllPropertiesWithAnInaccessibleSetter();
            CreateMap<WeChatUserInfoDto, WeChatUserInfoEntity>()
                .ForMember(p => p.Sex, dto => dto.MapFrom(s =>s.Sex.HasValue?s.Sex.ToString():null))
                .IgnoreAllPropertiesWithAnInaccessibleSetter();
            CreateMap<WeChatUserDto, WeChatUserInfoEntity>()
                .ForMember(p => p.Sex, dto => dto.MapFrom(s => s.Sex.HasValue?((WeChatUserSexType)Enum.ToObject(typeof(WeChatUserSexType),s.Sex.Value)).ToString():WeChatUserSexType.None.ToString()))
                .ForMember(p => p.TagidList, dto => dto.MapFrom(s => string.Join(',', s.TagidList)))
                .IgnoreAllPropertiesWithAnInaccessibleSetter();
        }
    }
}
